/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mvc.example.presentation.model;

import java.util.List;
import javax.swing.table.AbstractTableModel;
import mvc.example.bussines.domain.Student;

/**
 *
 * @author Zeta
 */
public class StudentsTableModel extends AbstractTableModel {

    private List<Student> students;

    public StudentsTableModel(List<Student> students) {
        this.students = students;
    }

    public List<Student> getStudents() {
        return students;
    }
    
    public Student getStudent(int rowIndex) {
        return students.get(rowIndex);
    }

    public void setStudents(List<Student> students) {
        this.students = students;
        fireTableDataChanged();
    }

    @Override
    public String getColumnName(int columnIndex) {
        switch (columnIndex) {
            case 0:
                return "Legajo";
            case 1:
                return "Nombre";
            case 2:
                return "Apellido";
            case 3:
                return "DNI";
            default:
                throw new IndexOutOfBoundsException("No existe numero de columna:" + columnIndex);
        }

    }

    @Override
    public int getRowCount() {
        return students.size();
    }

    @Override
    public int getColumnCount() {
        return 4;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        switch (columnIndex) {
            case 0:
                return students.get(rowIndex).getStudentId();
            case 1:
                return students.get(rowIndex).getFirstname();
            case 2:
                return students.get(rowIndex).getLastname();
            case 3:
                return students.get(rowIndex).getDni();
            default:
                throw new IndexOutOfBoundsException("No existe numero de columna:" + columnIndex);
        }
    }
    
}
